package com.hhs.storage.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhs.storage.bean.Comsumer;
import com.hhs.storage.bean.Region;
import com.hhs.storage.bean.TypeDic;
import com.hhs.storage.service.BaseLogsService;
import com.hhs.storage.service.ComsumerService;
import com.hhs.storage.service.RegionService;
import com.hhs.storage.service.TypeDicService;
import com.hhs.storage.util.SysUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Order(value = 1)
public class InitSystemParamRunner implements CommandLineRunner {
    @Autowired
    public  BaseLogsService logsService;
    @Autowired
    private ComsumerService comsumerService;
    @Autowired
    private TypeDicService typeDicService;

    @Autowired
    private RegionService regionService;
    @Override
    public void run(String... args) throws Exception {
        System.out.println("执行方法");
        SysUtil.logsService=logsService;
        getComsumers();//获取所有客户信息
        getTypeDic();
        //区域管理用到，现在弃用
//        getRegionFj();
    }
    //获取福建的下属地区信息
    private void getRegionFj(){
        List<Region> fj = regionService.fj();

    }
    //获取所有客户数据
    public void getComsumers(){
        List<Comsumer> list=comsumerService.list();
        SysUtil.COMSUMER_LIST=list;

    }
    //获取所有字典
    public void  getTypeDic(){
        //查询合同类型
        QueryWrapper<TypeDic> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        List<TypeDic> list=typeDicService.list(queryWrapper);
        SysUtil.CONTRACT_TYPE_LIST.clear();
        SysUtil.MODEL_TYPE_LIST.clear();
        SysUtil.PAY_TYPE_LIST.clear();
        SysUtil.PAY_WAY_LIST.clear();
        SysUtil.PLAN_YWTYPE_LIST.clear();
        for (int i=0;i<list.size();i++){
            TypeDic typeDic=list.get(i);
            switch (typeDic.getKeyWord()){
                case SysUtil.KEY_CONTRACT_TYPE:
                    SysUtil.CONTRACT_TYPE_LIST.add(typeDic);
                    break;
                case SysUtil.KEY_MODEL_TYPE:
                    SysUtil.MODEL_TYPE_LIST.add(typeDic);
                    break;
                case SysUtil.KEY_PAY_TYPE:
                    SysUtil.PAY_TYPE_LIST.add(typeDic);
                    break;
                case SysUtil.KEY_PAY_WAY:
                    SysUtil.PAY_WAY_LIST.add(typeDic);
                    break;
                case SysUtil.KEY_PLAN_YWTYPE:
                    SysUtil.PLAN_YWTYPE_LIST.add(typeDic);
                    break;
            }
        }

    }
}
